import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:saas_order_meal/saas_order_meal.dart';
import 'package:saas_order_meal/viewmodel/select_place_view_model.dart';

import '../net/net_response/elser_week_bind_info.dart';

class SelectPlacePage extends BaseStatefulMvvmWidget {
  final dynamic orderModelId;
  final dynamic bindSiteId;
  final dynamic bindUseType;
  List<CanUseSiteList> siteList = [];

  SelectPlacePage(
      {required this.orderModelId,
      this.bindSiteId,
      this.bindUseType,
      required this.siteList});

  @override
  State<StatefulWidget> createState() => _SelectPlaceState();
}

Future<dynamic> showSelectSite(BuildContext context,
    {required dynamic orderModelId,
    required List<CanUseSiteList> siteList,
    dynamic bindSiteId,
    dynamic bindUseType}) async {
  return await showModalBottomSheet(
      context: context,
      builder: (context) {
        return SelectPlacePage(
          orderModelId: orderModelId,
          siteList: siteList,
          bindSiteId: bindSiteId,
          bindUseType: bindUseType,
        );
      },
      backgroundColor: Colors.transparent);
}

class _SelectPlaceState
    extends BaseMvvmState<SelectPlaceViewModel, SelectPlacePage> {
  @override
  Widget? buildLoadingContentView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        CommonText('选择场所/用餐方式', textSize: 24, fontWeight: FontWeight.bold),
        SizedBox(
          height: 20,
        ),
        CommonText('场所'),
        SizedBox(
          height: 16,
        ),
        Wrap(
          spacing: 10,
          runSpacing: 10,
          children: widget.siteList
              .map((e) => Text(
                    e.siteName ?? "",
                    style: TextStyle(
                        color: e == viewModel.selectSite
                            ? Colors.white
                            : Color(0xff666666)),
                  )
                      .addToContainer(
                          decoration: BoxDecoration(
                              color: e == viewModel.selectSite
                                  ? SaasOrderMeal.mainColor
                                  : Colors.white,
                              border: Border.all(
                                  color: e == viewModel.selectSite
                                      ? SaasOrderMeal.mainColor
                                      : Colors.grey,
                                  width: 1),
                              borderRadius: 20.borderRadius),
                          padding:
                              EdgeInsets.symmetric(horizontal: 16, vertical: 4))
                      .onTap(() {
                    setState(() {
                      viewModel.selectSite = e;
                      if(SaasOrderMeal.useNetUseType){
                        viewModel.foodTypeSelectList = e.useType;
                      }
                    });
                  }))
              .toList(),
        ),
        SizedBox(
          height: 16,
        ),
        CommonText('用餐方式'),
        SizedBox(
          height: 16,
        ),
        Wrap(
          spacing: 10,
          runSpacing: 10,
          children: viewModel.foodTypeSelectList
              .map((e) => Text(
                    e.name ?? "",
                    style: TextStyle(
                        color: e == viewModel.selectFoodType
                            ? Colors.white
                            : Color(0xff666666)),
                  )
                      .addToContainer(
                          decoration: BoxDecoration(
                              color: e == viewModel.selectFoodType
                                  ? SaasOrderMeal.mainColor
                                  : Colors.white,
                              border: Border.all(
                                  color: e == viewModel.selectFoodType
                                      ? SaasOrderMeal.mainColor
                                      : Colors.grey,
                                  width: 1),
                              borderRadius: 20.borderRadius),
                          padding:
                              EdgeInsets.symmetric(horizontal: 16, vertical: 4))
                      .onTap(() {
                    setState(() {
                      viewModel.selectFoodType = e;
                    });
                  }))
              .toList(),
        ),
        SizedBox(
          height: 30,
        ),
        TextButton(
          onPressed: () {
            viewModel.applySelect();
          },
          child: CommonText('下一步', textColor: Colors.white),
          style: ButtonStyle(
            shape: MaterialStateProperty.all(StadiumBorder()),
            minimumSize: MaterialStateProperty.all(Size(double.infinity, 44)),
            backgroundColor: MaterialStateProperty.all(SaasOrderMeal.mainColor),
          ),
        ),
        SizedBox(
          height: 20,
        )
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget.addToContainer(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.vertical(top: 20.radius)),
        padding: EdgeInsets.only(left: 16, right: 16, top: 30));
  }

  @override
  SelectPlaceViewModel createViewModel() {
    return SelectPlaceViewModel(context, orderModelId: widget.orderModelId,siteList: widget.siteList);
  }

  @override
  void onRetryClick() {}
}
